package parameterized_type;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CollectionUtils<E> {
    private List<E> data = new ArrayList<>();

    public void add(E element) {
        data.add(element);
    }

    public E randomSelect() {
        int idx = new Random().nextInt(data.size());
        return data.get(idx);
    }

    public static void main(String[] args) {
        CollectionUtils<String> utils = new CollectionUtils<>();
        utils.add("a");
        utils.add("b");
        utils.add("c");
        utils.add("as");
        System.out.println(utils.randomSelect());
        System.out.println(utils.randomSelect());
        System.out.println(utils.randomSelect());
        System.out.println(utils.randomSelect());
    }

}
